<template>
    
  <div class="big">
    <div class="box">
      <div class="img">
        <img src="../../public/浪哩个啷.gif" alt="" />
      </div>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm">
        <el-form-item prop="username">
          <el-input
            v-model="ruleForm.username"
            prefix-icon="el-icon-user-solid"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            v-model="ruleForm.password"
            prefix-icon="el-icon-lock"
          ></el-input>
        </el-form-item>
        <el-form-item style="float:right">
          <el-button type="primary" @click="submitForm('ruleForm')"
            >登录</el-button
          >
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import {login} from '../api/user'
export default {
  name: "",
  data() {
    return {
      ruleForm: {
        username: "admin",
        password: "123456",
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  computed: {},
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(async(valid) => {
          if (!valid) return;
        const {data:res} = await login(this.ruleForm)
        console.log(res);
        if(res.meta.status !== 200 ) return this.$message.error(res.meta.msg)
        this.$message.success(res.meta.msg)
        window.sessionStorage.setItem("token", res.data.token);
        this.$router.push("/home");
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      
    },
  },
};
</script>

<style lang="scss" scoped>
.big {
  height: 100%;
  background: #2b4b6b;
  .box {
    background-color: #fff;
    position: absolute;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 10px #ddd;
    width: 450px;
    height: 304px;
    border-radius: 3px;
    top: 50%;
    .img {
      width: 130px;
      height: 130px;
      padding: 10px;
      border: 1px solid #efefef;
      border-radius: 50%;
      position: absolute;
      left: 140px;
      top: -96px;
      background: rosybrown;
      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background-color: #efefef;
      }
    }
    .el-form {
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      padding: 0 20px;
      box-sizing: border-box;
    }
  }
}
</style>
